import request from '@/config/axios'

export interface PageParam {
  pageNo: number
  pageSize: number
}

export interface EvalPlanVO {
  id?: number
  planName: string
  planCode: string
  batchName?: string
  professionId: number
  professionName: string
  professionCode: string
  applicableLevels?: string
  kpyrName?: string
  evaluationMethod: string
  templateId?: number
  registrationStartDate: string
  registrationEndDate: string
  evaluationStartDate: string
  evaluationEndDate: string
  planStatus: number
  targetAudience?: string
  targetDepartments?: string
  targetPositions?: string
  maxPeoplePerPlan?: number
  contactPerson?: string
  contactPhone?: string
  contactEmail?: string
  planDescription?: string
  createTime?: Date
}

export interface EvalPlanPageReqVO extends PageParam {
  planCode?: string
  planName?: string
  professionCode?: string
  professionName?: string
  evaluationMethod?: string
  templateId?: number
  planStatus?: number
  registrationStartDate?: string[]
  evaluationStartDate?: string[]
  createTime?: Date[]
}

export interface EvalPlanApproveReqVO {
  id: number
  approved: boolean
  comments?: string
}

export interface EvalPlanCancelReqVO {
  id: number
  reason: string
}

// 查询评价计划分页
export const getPlanPage = (params: EvalPlanPageReqVO) => {
  return request.get({ url: '/eval/plan/page', params })
}

// 查询评价计划详情
export const getPlan = (id: number) => {
  return request.get({ url: '/eval/plan/get?id=' + id })
}

// 新增评价计划
export const createPlan = (data: EvalPlanVO) => {
  return request.post({ url: '/eval/plan/create', data })
}

// 修改评价计划
export const updatePlan = (data: EvalPlanVO) => {
  return request.put({ url: '/eval/plan/update', data })
}

// 删除评价计划
export const deletePlan = (id: number) => {
  return request.delete({ url: '/eval/plan/delete?id=' + id })
}

// 导出评价计划
export const exportPlan = (params: EvalPlanPageReqVO) => {
  return request.download({ url: '/eval/plan/export-excel', params })
}

// 根据状态获得评价计划列表
export const getPlanListByStatus = (planStatus: number) => {
  return request.get({ url: '/eval/plan/list-by-status?planStatus=' + planStatus })
}

// 提交计划审批
export const submitPlanForApproval = (id: number) => {
  return request.put({ url: '/eval/plan/submit-approval?id=' + id })
}

// 审批计划
export const approvePlan = (data: EvalPlanApproveReqVO) => {
  return request.put({ url: '/eval/plan/approve', data })
}

// 发布计划
export const publishPlan = (id: number) => {
  return request.put({ url: '/eval/plan/publish?id=' + id })
}

// 开始评价
export const startEvaluation = (id: number) => {
  return request.put({ url: '/eval/plan/start?id=' + id })
}

// 完成评价
export const completeEvaluation = (id: number) => {
  return request.put({ url: '/eval/plan/complete?id=' + id })
}

// 取消计划
export const cancelPlan = (data: EvalPlanCancelReqVO) => {
  return request.put({ url: '/eval/plan/cancel', data })
}

// 获取计划统计信息
export const getPlanStatistics = (id: number) => {
  return request.get({ url: '/eval/plan/statistics?id=' + id })
}

// 检查计划是否可以删除
export const canDeletePlan = (id: number) => {
  return request.get({ url: '/eval/plan/can-delete?id=' + id })
}

// 检查计划是否可以修改
export const canUpdatePlan = (id: number) => {
  return request.get({ url: '/eval/plan/can-update?id=' + id })
}
